<?php
	class UserAction extends Action{
		public function index(){
			$m = M('User');
			$arr = $m->select();
			$this->assign('data',$arr);
			$this->display();
		}
		public function delete(){
			$id = $_GET['id'];
			$m = M('User');
			$count = $m->delete($id);
			if($count > 0){
				$this->success('delete success');
			}
			else $this->error('delete error');
		}
		
		public function modify(){
			$id = $_GET['id'];
			$m = M('User');
			$user = $m->find($id);
			$this->assign('data',$user);
			$this->display();
		}
		
		public function update(){
			$user['id'] = $_POST['id'];
			$user['name'] = $_POST['name'];
			$user['sex'] = $_POST['sex'];
			$m = M('User');
			$count = $m->save($user);
			if($count > 0){
				$this->success('update success','index');
			}
			else {
				$this->error('update error','index');
			}
		}
		
		public function add(){
			$this->display();
		}
		
		public function create(){
			$user['name'] = $_POST['name'];
			$user['sex'] = $_POST['sex'];
			$m = M('User');
			$count = $m->add($user);
			if($count > 0){
				$this->success('add success','index');
			}
			else {
				$this->error('add error','index');
			}
		}
	}

?>